package com.dc.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.ReflectionException;

@Slf4j
public class MateMetaObjectHandler implements MetaObjectHandler {


    //tenant_id 对应实体类的属性名称，而非数据库字段名
    @Override
    public void insertFill(MetaObject metaObject) {
        try {
            //插入填充
            this.strictInsertFill(metaObject, "tenantId", String.class, getUserUniqueId());
        } catch (ReflectionException e) {
            log.warn(">>> MateMetaObjectHandler处理过程中无相关字段，不做处理");
        }

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        //修改填充

    }


    /**
     * 获取用户租户id
     */
    private String getUserUniqueId() {
        try {
            return "123";
        } catch (Exception e) {
            //如果获取不到就返回-1
            return "-1";
        }
    }

}
